import { Component, OnInit } from '@angular/core';

import { User } from '../../domain/user';

import { UserService } from '../../service/user.service';

@Component({
  selector: 'app-user-detail',
  templateUrl: './user-detail.component.html',
  styleUrls: ['./user-detail.component.css'],
  providers: [UserService]
})
export class UserDetailComponent implements OnInit {

  user: User;
  userUpdate: User;

  constructor(
    private userService: UserService,
  ) { }

  ngOnInit() {
    this.userService.getUserById(Number(localStorage.getItem('userId')))
      .then(res => {
        this.user = res;
        this.userUpdate = res;
      });

  }

  updateUser(): void {
    this.userService.updateUser(this.user)
      .then(() => {
        location.reload();
      });
  }

  reset():void{
    location.reload();
  }

}
